package com.star.security.authentication;

/**
 * 匿名身份验证
 *
 * @author yangzj
 */
public class AnonymousAuthenticationToken extends AuthenticationToken {

    public AnonymousAuthenticationToken(boolean authenticated) {
        super(null, null, null, null, null);
        super.setAuthenticated(authenticated);
    }

    /**
     * 是否未经验证
     *
     * @param authentication 身份验证
     * @return boolean
     */
    public static boolean isUnauthenticated(Authentication authentication) {
        return authentication instanceof AnonymousAuthenticationToken && !authentication.isAuthenticated();
    }

    /**
     * 未经验证
     *
     * @return {@link AnonymousAuthenticationToken}
     */
    public static AnonymousAuthenticationToken unauthenticated() {
        return new AnonymousAuthenticationToken(false);
    }

    /**
     * 已验证
     *
     * @return {@link AnonymousAuthenticationToken}
     */
    public static AnonymousAuthenticationToken authenticated() {
        return new AnonymousAuthenticationToken(true);
    }
}
